package frontend.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private TablePanel tablePanel;
	private JPanel menuPanel;
	private JPanel mainPanel;
	private JButton create;
	private JButton update;
	private JButton delete;
	private JPopupMenu popup;
	private JMenuItem updatePopup;
	private JMenuItem deletePopup;
	private static MainFrame instance = null;

	private MainFrame() {
		tablePanel = new TablePanel();
		mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		mainPanel.add(tablePanel, BorderLayout.CENTER);

		Dimension dim = new Dimension(80, 30);
		create = new JButton("Create");
		create.setPreferredSize(dim);
		update = new JButton("Update");
		update.setPreferredSize(dim);
		delete = new JButton("Delete");
		delete.setPreferredSize(dim);

		menuPanel = new JPanel();
		menuPanel.setPreferredSize(dim);
		;
		menuPanel.setLayout(new FlowLayout());
		menuPanel.add(create);
		menuPanel.add(update);
		menuPanel.add(delete);
		mainPanel.add(menuPanel, BorderLayout.EAST);

		popup = new JPopupMenu();
		updatePopup = new JMenuItem("Update");
		popup.add(updatePopup);
		deletePopup = new JMenuItem("Delete");
		popup.add(deletePopup);

		this.setContentPane(mainPanel);
		this.setBounds(100, 300, 700, 400);
		this.setResizable(false);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.pack();
	}

	public static synchronized MainFrame getInstance() {
		if (instance == null) {
			instance = new MainFrame();
		}
		return instance;
	}

	public TablePanel getTablePanel() {
		return tablePanel;
	}

	public void setTablePanel(TablePanel tablePanel) {
		this.tablePanel = tablePanel;
	}

	public JPanel getMenuPanel() {
		return menuPanel;
	}

	public void setMenuPanel(JPanel menuPanel) {
		this.menuPanel = menuPanel;
	}

	public JPanel getMainPanel() {
		return mainPanel;
	}

	public void setMainPanel(JPanel mainPanel) {
		this.mainPanel = mainPanel;
	}

	public JButton getCreate() {
		return create;
	}

	public JButton getUpdate() {
		return update;
	}

	public JButton getDelete() {
		return delete;
	}

	public JPopupMenu getPopup() {
		return popup;
	}

	public void setPopup(JPopupMenu popup) {
		this.popup = popup;
	}

	public JMenuItem getUpdatePopup() {
		return updatePopup;
	}

	public void setUpdatePopup(JMenuItem updatePopup) {
		this.updatePopup = updatePopup;
	}

	public JMenuItem getDeletePopup() {
		return deletePopup;
	}

	public void setDeletePopup(JMenuItem deletePopup) {
		this.deletePopup = deletePopup;
	}

}
